// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Enrich;

public sealed partial class EnrichPolicy
{
	[JsonInclude, JsonPropertyName("elasticsearch_version")]
	public string? ElasticsearchVersion { get; set; }
	[JsonInclude, JsonPropertyName("enrich_fields")]
	[JsonConverter(typeof(SingleOrManyFieldsConverter))]
	public Elastic.Clients.Elasticsearch.Serverless.Fields EnrichFields { get; set; }
	[JsonInclude, JsonPropertyName("indices")]
	public Elastic.Clients.Elasticsearch.Serverless.Indices Indices { get; set; }
	[JsonInclude, JsonPropertyName("match_field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field MatchField { get; set; }
	[JsonInclude, JsonPropertyName("name")]
	public Elastic.Clients.Elasticsearch.Serverless.Name? Name { get; set; }
	[JsonInclude, JsonPropertyName("query")]
	public Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? Query { get; set; }
}

public sealed partial class EnrichPolicyDescriptor<TDocument> : SerializableDescriptor<EnrichPolicyDescriptor<TDocument>>
{
	internal EnrichPolicyDescriptor(Action<EnrichPolicyDescriptor<TDocument>> configure) => configure.Invoke(this);

	public EnrichPolicyDescriptor() : base()
	{
	}

	private string? ElasticsearchVersionValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fields EnrichFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices IndicesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field MatchFieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Name? NameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> QueryDescriptorAction { get; set; }

	public EnrichPolicyDescriptor<TDocument> ElasticsearchVersion(string? elasticsearchVersion)
	{
		ElasticsearchVersionValue = elasticsearchVersion;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> EnrichFields(Elastic.Clients.Elasticsearch.Serverless.Fields enrichFields)
	{
		EnrichFieldsValue = enrichFields;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Serverless.Indices indices)
	{
		IndicesValue = indices;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> MatchField(Elastic.Clients.Elasticsearch.Serverless.Field matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> MatchField<TValue>(Expression<Func<TDocument, TValue>> matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> MatchField(Expression<Func<TDocument, object>> matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> Name(Elastic.Clients.Elasticsearch.Serverless.Name? name)
	{
		NameValue = name;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public EnrichPolicyDescriptor<TDocument> Query(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(ElasticsearchVersionValue))
		{
			writer.WritePropertyName("elasticsearch_version");
			writer.WriteStringValue(ElasticsearchVersionValue);
		}

		writer.WritePropertyName("enrich_fields");
		JsonSerializer.Serialize(writer, EnrichFieldsValue, options);
		writer.WritePropertyName("indices");
		JsonSerializer.Serialize(writer, IndicesValue, options);
		writer.WritePropertyName("match_field");
		JsonSerializer.Serialize(writer, MatchFieldValue, options);
		if (NameValue is not null)
		{
			writer.WritePropertyName("name");
			JsonSerializer.Serialize(writer, NameValue, options);
		}

		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor<TDocument>(QueryDescriptorAction), options);
		}
		else if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class EnrichPolicyDescriptor : SerializableDescriptor<EnrichPolicyDescriptor>
{
	internal EnrichPolicyDescriptor(Action<EnrichPolicyDescriptor> configure) => configure.Invoke(this);

	public EnrichPolicyDescriptor() : base()
	{
	}

	private string? ElasticsearchVersionValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Fields EnrichFieldsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Indices IndicesValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field MatchFieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Name? NameValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> QueryDescriptorAction { get; set; }

	public EnrichPolicyDescriptor ElasticsearchVersion(string? elasticsearchVersion)
	{
		ElasticsearchVersionValue = elasticsearchVersion;
		return Self;
	}

	public EnrichPolicyDescriptor EnrichFields(Elastic.Clients.Elasticsearch.Serverless.Fields enrichFields)
	{
		EnrichFieldsValue = enrichFields;
		return Self;
	}

	public EnrichPolicyDescriptor Indices(Elastic.Clients.Elasticsearch.Serverless.Indices indices)
	{
		IndicesValue = indices;
		return Self;
	}

	public EnrichPolicyDescriptor MatchField(Elastic.Clients.Elasticsearch.Serverless.Field matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor MatchField<TDocument, TValue>(Expression<Func<TDocument, TValue>> matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor MatchField<TDocument>(Expression<Func<TDocument, object>> matchField)
	{
		MatchFieldValue = matchField;
		return Self;
	}

	public EnrichPolicyDescriptor Name(Elastic.Clients.Elasticsearch.Serverless.Name? name)
	{
		NameValue = name;
		return Self;
	}

	public EnrichPolicyDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.Query? query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public EnrichPolicyDescriptor Query(Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public EnrichPolicyDescriptor Query(Action<Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (!string.IsNullOrEmpty(ElasticsearchVersionValue))
		{
			writer.WritePropertyName("elasticsearch_version");
			writer.WriteStringValue(ElasticsearchVersionValue);
		}

		writer.WritePropertyName("enrich_fields");
		JsonSerializer.Serialize(writer, EnrichFieldsValue, options);
		writer.WritePropertyName("indices");
		JsonSerializer.Serialize(writer, IndicesValue, options);
		writer.WritePropertyName("match_field");
		JsonSerializer.Serialize(writer, MatchFieldValue, options);
		if (NameValue is not null)
		{
			writer.WritePropertyName("name");
			JsonSerializer.Serialize(writer, NameValue, options);
		}

		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.QueryDsl.QueryDescriptor(QueryDescriptorAction), options);
		}
		else if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}